﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using He.Common;

namespace He.Web.manage.network
{
    public partial class list : He.Web.UI.Manage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                chkLoginLevel("viewnetwork");
                CookieHelper.Set("LastListUrl", Request.RawUrl);    //保存最后一次访问的列表页Url
                RptBind();
            }
        }

        #region 数据绑定
        private void RptBind()
        {
            BLL.network bll = new BLL.network();
            rptInfo.DataSource = bll.GetList(string.Format("lang='{0}'", lang));
            rptInfo.DataBind();
        }
        #endregion

        protected void lbtnDel_Click(object sender, EventArgs e)
        {
            chkLoginLevel("delnetwork");
            BLL.network bll = new BLL.network();
            for (int i = 0; i < rptInfo.Items.Count; i++)
            {
                CheckBox cb = (CheckBox)rptInfo.Items[i].FindControl("Check");
                int id = int.Parse(((HiddenField)rptInfo.Items[i].FindControl("HiddenId")).Value);
                if (cb.Checked)
                {
                    //删除
                    Model.network model = bll.GetModel(id);
                    bll.Delete(id);
                }
            }
            SaveLogs("[营销网络管理]批量删除");
            JscriptPrint("批量删除成功啦！", Request.RawUrl, "Success");
        }

        //推荐
        protected void ibtnRed_Command(object sender, CommandEventArgs e)
        {
            chkLoginLevel("editnetwork");
            int id = Convert.ToInt32(e.CommandArgument);
            BLL.network bll = new BLL.network();
            Model.network model = bll.GetModel(id);
            model.is_show = model.is_show == 1 ? 0 : 1;
            bll.Update(model);
            SaveLogs(string.Format("[营销网络管理]修改属性:{0}", model.title));
            Response.Redirect(Request.RawUrl);
        }
    }
}
